import 'package:base_flutter/base_flutter.dart';
import 'package:base_flutter/src/utils/ext_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TitleValueWidget extends StatelessWidget {
  final String name;
  final Color color;
  final bool showArrow;
  final bool isRequired;
  Color textColor;
  Color nameColor;
  String text;
  String hint;
  EdgeInsets padding;
  TextAlign textAlign;
  Widget? rightWeight;
  double fontSize;
  int titleWeight = 2;
  int contentWeight = 3;

  TitleValueWidget(this.name,
      {this.color = Colors.white,
        this.showArrow = true,
        this.isRequired = false,
        this.text = "",
        this.textColor = Colors.black,
        this.nameColor = Colors.black,
        this.fontSize = 16,
        this.hint = "请选择",
        this.titleWeight = 2,
        this.contentWeight = 3,
        this.padding = const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
        this.textAlign = TextAlign.start,this.rightWeight});

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        isRequired
            ? Text.rich(TextSpan(
            text: "*",
            style: TextStyle(color: Colors.red, fontSize: fontSize),
            children: [
              TextSpan(
                text: name,
                style: TextStyle(color: nameColor, fontSize: fontSize),
              )
            ])).setWeight(titleWeight)
            : Text(
          name,
          textAlign: TextAlign.start,
          style: TextStyle(color: nameColor, fontSize: fontSize,height: 1.2),
        ).setWeight(titleWeight),
        Row(
          children: [
            Text(text.isNullOrEmpty()?hint:text,
              style: TextStyle(
                  height: 1.2,
                  fontSize: fontSize, color: text.isNullOrEmpty()?Colors.grey:textColor
              ),textAlign: textAlign,).setWeight(1),
            showArrow
                ? this.rightWeight??Icon(
              Icons.arrow_forward_ios_rounded,
              size: 15,
              color: Colors.grey,
            )
                : Container()
          ],
        )
            .setWeight(contentWeight),

      ],
    ).addToContainer(
        color: color,
        padding: padding);
  }
}
